<!-- 
  @name: 余量报警设置
  @date: 2020.3.13
 -->
<template>
	<view class="content">
		<!-- 余量报警设置 -->
		<view class="set_num">
			<view class="num_int">
				<view class="_tip">余量报警值</view>
				<view class="_btn les" @tap="count(1)"></view>
				<view class="_num"><input type="digit" v-model.number="volnum" /></view>
				<view class="_btn add" @tap="count(2)"></view>
				<view class="_tip2">%</view>
			</view>
		</view>
		<view class="note">余量报警值:加注机余量达到报警值时，将通过微信公众号发送余量提醒通知。</view>
		
		<!-- 按钮 -->
		<button class="btn_submit" @tap="submit">设置</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				volnum: 10  //余量报警值
			}
		},
		onLoad() {
			this.getNum();
		},
		methods: {
			//增加减少领取数
			count(n) {
				if(n === 1) {
					if(this.volnum > 0) this.volnum -= 1;
				} else {
					if(this.volnum < 100) this.volnum += 1;
				}
			},
			//提交
			submit() {
				if(this.volnum === '' || this.volnum < 0 || this.volnum > 100) {
					this.$showToast('请输入正确的余量报警值！');
					return;
				}
				this.$http({
					url: this.$api.accountUrl + 'addfilloperatorinfo',
					data: {
						action: 1,
						alarmValue: this.volnum / 100
					}
				}).then(res => {
					this.$successToast('保存成功！');
					this.$sucBack();
				});
			},
			//获取原本的数值
			getNum() {
				let operaId = JSON.parse(this.$store.state.userinfo).operaId;
				this.$http({
					url: this.$api.siteUrl + 'getfilloperatordetail',
					data: {
						operaId: operaId
					}
				}).then(res => {
					this.volnum = res.alarmValue * 100;
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: $color-white;
	}
	
	/* 余量报警设置 */
	.note {
		width: 750rpx;
		margin-top: 80rpx;
		padding-left: 40rpx;
		padding-right: 57rpx;
		color: $color-grey;
		font-size: 24rpx;
		line-height: 40rpx;
	}
	
	/* 按钮 */
	.btn_submit {
		position: fixed;
		bottom: 0;
	}
</style>
